package com.yzc.controller;


import com.yzc.model.entity.notification.MessageCount;
import com.yzc.model.entity.notification.MessageDto;
import com.yzc.model.entity.notification.Notification;
import com.yzc.model.entity.notification.Users;
import com.yzc.service.GetUsersService;
import com.yzc.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notification")
public class GetUsersController {

    @Autowired
    private GetUsersService getUsersService;
    @Autowired
    private NotificationService notificationService;

    @PostMapping("/loadAllUsers")
    public List<Users> loadAllUsers(@RequestParam("acceptuserid") Integer acceptuserid) {

        return getUsersService.loadAllUsers(acceptuserid);
    }

    //    根据acceptuserid来进行用户消息条数的查询
    @PostMapping("/selectByacceptuserid")
    public List<MessageCount> selectByacceptuserid(@RequestParam("acceptuserid") Integer acceptuserid) {
        return notificationService.selectByacceptuserid(acceptuserid);
    }

    //    1.根据senduserid和acceptuserid来进行用户消息的查询
    @PostMapping("/getMessageBySenduserid")
    public List<Notification> selectBySenduserid(
            @RequestParam("senduserid") Integer senduserid,
            @RequestParam("acceptuserid") Integer acceptuserid) {
        List<Notification> notifications = notificationService.selectBySenduserid(senduserid, acceptuserid);
        return notifications;
    }

    //    2.将用户消息的状态改为已读
    @PostMapping("/updateState")
    public void updateState(
            @RequestParam("senduserid") Integer senduserid,
            @RequestParam("acceptuserid") Integer acceptuserid) {
        notificationService.updateState(senduserid, acceptuserid);
    }


    @PostMapping("/sendMessageBysenduserid")
    public void sendBysenduserid(
            @RequestParam("acceptuserid") Integer senduserid,
            @RequestParam("senduserid") Integer acceptuserid,
            @RequestParam("content") String content) {
        notificationService.sendBysenduserid(senduserid, acceptuserid, content);
    }

    @PostMapping("/sendGroupMessage")
    public void sendGroupMessage(@RequestBody List<MessageDto> messageDtos) {
        // 这里应该将messageDtos作为参数传递给MyBatis相关方法，确保参数名和类型与SQL映射文件中的要求匹配
        notificationService.sendGroupMessage(messageDtos);
    }

    @PostMapping("/sendGroupMessageByacceptuserid")
    public List<Notification> sendGroupMessageByacceptuserid(@RequestParam("acceptuserid") Integer acceptuserid) {
        return notificationService.sendGroupMessageByacceptuserid(acceptuserid);
    }


}